In a multitasking computer system, tasks that require exclusive access to a system resource or a critical section of code are typically required to obtain a latch to serialize such access. Only one task (or thread/process) can hold a latch at any particular time. Other tasks seeking access to the system resource will wait on the latch and are suspended until the latch is freed by the current holder of the latch.
The common method of implementing a latch in application software is for all waiters to wait on a lower level primitive provided by the operating system. Common primitives include semaphores and message queues (depending on the implementation of the latch). Tasks requesting a latch (“requesters”) will, after unsuccessfully attempting to get the latch, wait on the appropriate operating system resource. Because the requesters are waiting on an operating system primitive, the operating system suspends the requesters waiting on the latch (in fact the lower level primitive) while a task continues to hold the latch. When the latch is freed, the operating system permits the requesting suspended tasks to resume. The result is that each of the requesting tasks competes with each other to obtain the latch. As is apparent, as the number of tasks increases, the resumption of each requester task when a latch is freed will cause a greater use of system resources (including CPU time) as each task will seek to acquire the operating system primitive.
Prior art systems provide for assigning priorities and dispatch classes to program threads to permit application programs to influence the schedule of execution for program threads (see for example U.S. Pat. No. 5,630,128, Farrell). However, such systems do not prevent the contention for the operating system primitives described above for threads having the same priority in the same dispatch class.
It is therefore desirable to have a system that permits tasks to request a latch without placing excessive demands on system resources when the latch is released and requester threads seek to obtain the latch.